<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>外间距</title>
    <style>
        body {
            margin: 0;
        }

        .fu {
            background-color: lime;
            /* 2.父子粘连(贴边):
                首/尾元素的上/下外间距会超出父元素的范围，需要给父元素设置BFC保护*/
            overflow: hidden; /* BFC结界*/

        }

        .fu > div {
            width: 100px;
            height: 100px;
            background-color: rgba(0, 0, 255, 0.5);
            border: 2px solid #00f;
            color: #fff;
            font-size: 25px;
            font-weight: bold;
        }

        /* 相邻兄弟垂直方向的外间距取大值显示 不会叠加*/
        .z1 {
            margin-bottom: 30px;
            margin-top: 50px;
        }

        .z2 {
            margin-top: 50px;
        }

        .z3 {
            margin: 10px;
            margin: 10px 20px;
            margin: 10px 20px 30px;
            margin: 10px 20px 30px 40px;
            margin: 0 auto;  /* 上下为0   水平居中*/
        }
        .z4 {
            margin-bottom: 50px;
        }
        span{
            border: 2px solid #f00;
        }
        .s1{
            /*行内元素上下间距不生效*/
            margin:30px
        }
    </style>
</head>
<body>
<span>span1</span><span class="s1">span2</span><span>span3</span>

<!--.fu>.z*4 tab补全-->
<div class="fu">
    <div class="z1">子元素1</div>
    <div class="z2">子元素2</div>
    <div class="z3">子元素3</div>
    <div class="z4">子元素4</div>
</div>

</body>
</html>